function [date_diff,prof_diff,data_diff]= transform_2Dmat(date_dec,prof,data);
% Subroutine permettant de transformer
% les donnees � 1D en matrice a 2D.
%
% G. Charria 01/2006 - Modif. 04/2006 (WOCE)
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


switch nargin
 case 3 

  % ---- Estimation du nombre de dates differentes
  a=sort(date_dec);
  n_dat=1;
  date_diff1(n_dat)=a(1);
  for ia=2:size(a,2)
    if (a(ia) > a(ia-1))
      n_dat=n_dat+1;
    end
    date_diff1(n_dat)=a(ia);
  end
    
  
  %disp(['Nombre de Dates differentes: ',num2str(n_dat)])
  

  
  

  % ---- Reduction des profondeurs pour les 500 premiers metres.
  prof_diff(1:size(prof,1),1:size(prof,2))=NaN;
  data_diff(1:size(prof,1),1:size(prof,2))=NaN;
  date_diff(1:size(prof,1),1:size(prof,2))=NaN;
  
  
  for idate=1:size(prof,1)
  
    index2=find(prof(idate,:) <= 500);
    prof_diff(idate,1:size(index2,2))=prof(idate,index2);
    data_diff(idate,1:size(index2,2))=data(idate,index2);
    clear index2;
    date_diff(idate,:)=date_diff1(idate);
  end
  
  

  
 otherwise
  disp('Wrong number of arguments'); 
  prof_diff=[]; 
  date_diff=[];
  data_diff=[];
  return
end